// doctor/index.js
Page({
  data: {
    // 当前选中的科室ID（0表示全部）
    currentDepartment: 0,

    // 科室列表
    departmentList: [
      {
        id: 1,
        name: '不孕不育'
      },
      {
        id: 2,
        name: '排卵障碍'
      },
      {
        id: 3,
        name: '阳痿早泄'
      },
      {
        id: 4,
        name: '性功能障碍'
      },
      {
        id: 5,
        name: '生殖感染'
      },
      {
        id: 6,
        name: '泌尿感染'
      },
      {
        id: 7,
        name: '包皮包茎'
      },
      {
        id: 8,
        name: '前列腺增生'
      }
    ],

    // 医生列表
    doctorList: [
      {
        id: 1,
        name: '张医生',
        title: '主任医师',
        brief: '从医20年',
        specialty: '擅长各类不孕不育、排卵障碍等疾病的诊断与治疗',
        avatar: '/images/doctor1.png',
        departmentId: 1,
        schedule: [
          { day: '周一', time: '上午' },
          { day: '周三', time: '下午' },
          { day: '周五', time: '全天' }
        ]
      },
      {
        id: 2,
        name: '李医生',
        title: '副主任医师',
        brief: '从医15年',
        specialty: '擅长男性泌尿系统疾病、性功能障碍等疾病的诊断与治疗',
        avatar: '/images/doctor2.png',
        departmentId: 3,
        schedule: [
          { day: '周二', time: '上午' },
          { day: '周四', time: '下午' },
          { day: '周六', time: '上午' }
        ]
      },
      {
        id: 3,
        name: '王医生',
        title: '主治医师',
        brief: '从医10年',
        specialty: '擅长生殖感染、泌尿感染等疾病的诊断与治疗',
        avatar: '/images/doctor3.png',
        departmentId: 5,
        schedule: [
          { day: '周一', time: '下午' },
          { day: '周三', time: '上午' },
          { day: '周日', time: '全天' }
        ]
      },
      {
        id: 4,
        name: '刘医生',
        title: '主任医师',
        brief: '从医25年',
        specialty: '擅长前列腺增生、包皮包茎等疾病的诊断与治疗',
        avatar: '/images/doctor4.png',
        departmentId: 7,
        schedule: [
          { day: '周二', time: '全天' },
          { day: '周四', time: '上午' },
          { day: '周六', time: '下午' }
        ]
      },
      {
        id: 5,
        name: '陈医生',
        title: '副主任医师',
        brief: '从医18年',
        specialty: '擅长性功能障碍、排卵障碍等疾病的诊断与治疗',
        avatar: '/images/doctor5.png',
        departmentId: 2,
        schedule: [
          { day: '周一', time: '上午' },
          { day: '周五', time: '下午' },
          { day: '周日', time: '上午' }
        ]
      }
    ],

    // 筛选后的医生列表
    filteredDoctorList: []
  },

  onLoad: function (options) {
    // 初始化筛选后的医生列表为全部医生
    this.setData({
      filteredDoctorList: this.data.doctorList
    });
  },

  // 根据科室筛选医生
  filterByDepartment: function(e) {
    const departmentId = e.currentTarget.dataset.id;
    
    let filteredDoctorList = [];
    if (departmentId === 0) {
      // 选择全部科室
      filteredDoctorList = this.data.doctorList;
    } else {
      // 根据科室ID筛选医生
      filteredDoctorList = this.data.doctorList.filter(doctor => doctor.departmentId === departmentId);
    }
    
    this.setData({
      currentDepartment: departmentId,
      filteredDoctorList: filteredDoctorList
    });
  },

  // 导航到医生详情页面
  navigateToDoctorDetail: function(e) {
    const doctorId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/doctor/detail?id=${doctorId}`
    });
  },

  // 预约挂号
  makeAppointment: function(e) {
    const doctorId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/appointment/make?doctorId=${doctorId}`
    });
  }
});